home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / BoingBag1 / Contributions / InstallerNG / GUI-API / example / igui_AskChoice.c < prev    next >
C/C++ Source or Header  |  1999-10-31  |  6KB  |  186 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. /********************************************************************
  6.  *
  7.  *  DESCRIPTION
  8.  *
  9.  *  create and show the ASKCHOICE panel; this is a number of
  10.  *  MX buttons and related labels; the localenv->fe_Choices
  11.  *  is a List, which holds all the labels (every node->ln_Name)
  12.  *  and the related bitnumber (node->ln_Pri). see the installer
  13.  *  documentation for more infos about the sense of this bitnumber.
  14.  *  you should only use the first 32 nodes of the localenv->fe_Choices
  15.  *  list, because the long value, which you must return, has only
  16.  *  32 bits ;-)
  17.  *
  18.  *  IN:  application - pointer to the private application structure
  19.  *       localenv - the local environment of the related ASKBOOL
  20.  *                  function
  21.  *
  22.  *  OUT: a long value (see installer documentation, for how to build
  23.  *       this value!)
  24.  *
  25.  */
  26.  
  27. /********************************************************************
  28.  *
  29.  *  STATIC
  30.  *
  31.  */
  32.  
  33. static void __asm __saveds askchoice_hookfun(register __a2 APTR, register __a1 APTR *);
  34.  
  35. static const struct Hook askchoice_hook = { { NULL, NULL }, (VOID *) askchoice_hookfun, NULL, NULL };
  36.  
  37. /********************************************************************
  38.  *
  39.  *  EXTERN
  40.  *
  41.  */
  42.  
  43. /********************************************************************
  44.  *
  45.  *  PUBLIC
  46.  *
  47.  */
  48.  
  49. /********************************************************************
  50.  *
  51.  *  CODE
  52.  *
  53.  */
  54.  
  55. long __asm igui_AskChoice(register __a0 APTR application,
  56.                           register __a1 struct FunctionEnvironment *localenv)
  57. {
  58.   #ifdef DEBUG
  59.   DEBUG_MAKRO
  60.   #endif
  61.  
  62.   {
  63.     struct Application *app = (struct Application *) application;
  64.  
  65.     // the return value of this function
  66.     long retval = localenv->fe_Default;
  67.  
  68.     // for later use
  69.     APTR innergroup,
  70.  
  71.          // store all the radio-buttons here
  72.          choices[32],
  73.  
  74.          // the new object
  75.          obj = GroupObject,
  76.                  Child, TextObject,
  77.                    MUIA_Frame, MUIV_Frame_None,
  78.                    MUIA_Text_Contents, localenv->fe_Prompt,
  79.                    MUIA_Text_SetMin, TRUE,
  80.                    MUIA_Text_PreParse, "\33c",
  81.                  End,
  82.                  Child, innergroup = GroupObject,
  83.                    MUIA_Group_Horiz, TRUE,
  84.                    Child, HVSpace,
  85.                      // here we will put the radio buttons later
  86.                  End,
  87.                End;
  88.  
  89.     // clear the choices array
  90.     int i;
  91.     for (i=0; i<32; i++) { choices[i] = NULL; }
  92.  
  93.     if (!obj) { app->app_Error = GUIERROR_NO_GUI_OBJECT; }
  94.     else
  95.     {
  96.       // now dynamically create the labels and the radios and
  97.       // put them together into the inner group!
  98.       if (DoMethod(innergroup, MUIM_Group_InitChange))
  99.       {
  100.         int i,j;
  101.         char *label;
  102.         APTR radio;
  103.         struct Node *choicenode = sav_GetHead((struct List *) &(localenv->fe_Choices));
  104.         long num_choices = sav_ListLen((struct List *) &(localenv->fe_Choices)),
  105.              columns = num_choices/10 + 1,
  106.              rows = num_choices/columns,
  107.              choice_id;
  108.  
  109.         // care for odd number of choices!
  110.         if (num_choices > (rows * columns)) { rows++; }
  111.  
  112.         // go!
  113.         for (j=1; j<=columns; j++)
  114.         {
  115.           APTR choicelist = GroupObject,
  116.                               MUIA_Group_Columns, 2,
  117.                               Child, HVSpace,
  118.                               Child, HVSpace,
  119.                             End;
  120.  
  121.           if (choicelist && DoMethod(choicelist, MUIM_Group_InitChange))
  122.           {
  123.             for (i=1; (i<=rows) && choicenode; i++)
  124.             {
  125.               // the node ln_Name holds the name, ln_Pri holds the related bit-number
  126.               label = choicenode->ln_Name;
  127.               choice_id = choicenode->ln_Pri;
  128.               choicenode = sav_GetSucc(choicenode);
  129.  
  130.               DoMethod(choicelist, OM_ADDMEMBER, Label(label));
  131.               DoMethod(choicelist, OM_ADDMEMBER, radio = guistuff_InitRadio((retval==choice_id), FALSE));
  132.  
  133.               // the hook
  134.               if (radio)
  135.               {
  136.                 choices[choice_id] = radio;
  137.                 SetAttrs(radio, MUIA_UserData, choice_id, TAG_DONE);
  138.                 DoMethod(radio, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  139.                          MUIV_Notify_Self, 4, MUIM_CallHook, &askchoice_hook, &choices, &retval);
  140.               }
  141.             }
  142.             DoMethod(choicelist, OM_ADDMEMBER, HVSpace);
  143.             DoMethod(choicelist, OM_ADDMEMBER, HVSpace);
  144.             DoMethod(choicelist, MUIM_Group_ExitChange);
  145.           }
  146.  
  147.           DoMethod(innergroup, OM_ADDMEMBER, choicelist);
  148.         }
  149.  
  150.         // unteren space einfügen und fertig
  151.         DoMethod(innergroup, OM_ADDMEMBER, HVSpace);
  152.         DoMethod(innergroup, MUIM_Group_ExitChange);
  153.       }
  154.  
  155.       // maybee BACK (if specified) or respect the swing mode
  156.       if (localenv->fe_Back)         { guistuff_SetBackButton(app, TRUE); }
  157.       else if (!app->app_SWING_Mode) { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  158.  
  159.       // add the content to the gui!
  160.       guistuff_NewContent(app, obj);
  161.  
  162.       //
  163.       igui_WaitApp(app);
  164.     }
  165.  
  166.     // and done
  167.     if (localenv->fe_Back) { guistuff_SetBackButton(app, FALSE); }
  168.  
  169.     igui_EmptyPanel(app);
  170.     return(retval);
  171.   }
  172. }
  173.  
  174. /********************************************************************/
  175.  
  176. static void __asm __saveds askchoice_hookfun(register __a2 APTR obj, register __a1 APTR *data)
  177. {
  178.   // data[0] holds a pointer to the radio-array "choices"
  179.   // data[1] holds the address of the "retval"
  180.  
  181.   SetAttrs(((APTR *) data[0])[*((ULONG *) data[1])], MUIA_Selected, FALSE, TAG_DONE);
  182.   GetAttr(MUIA_UserData, obj, (APTR) data[1]);
  183. }
  184.  
  185.  
  186.